package samples.d2.lines 
{
	import adobe.utils.CustomActions;
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Shape;
	import flash.filters.GlowFilter;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.utils.getTimer;
	import flash.utils.setInterval;
	import samples.BaseSample;
	import shapes.shapes2D.curves.RoundPath;
	import shapes.shapes2D.distribution.Circular;
	import shapes.shapes2D.distribution.Disc;
	import shapes.shapes2D.distribution.random.PRNG;
	import shapes.shapes2D.distribution.RandomDistribution;
	import shapes.shapes2D.Dot;
	import shapes.shapes2D.Line;
	import utils.GeomUtils;
	
	/**
	 * @author Nicolas Barradeau
	 * http://en.nicoptere.net
	 */
	public class Lines7 extends BaseSample
	{
		
		private var p0:Point;
		private var p1:Point;
		private var p2:Point;
		private var points:Vector.<Point>;
		
		public function Lines7() 
		{
			
			var c:Point = new Point( sw/2, sh/2 );
			
			var r:int = 100;
			points = RandomDistribution.distribute( new Rectangle( 100,100,sw-200, sh-200), 250 );
			
			PRNG.seed = getTimer();
			var bd:BitmapData = new BitmapData( sw, sh, false, 0 );
			addChild( new Bitmap( bd ) );
			
			var canvas:Shape = new Shape();
			//interval = setInterval( update, 30 );
			//update();
		//}
		//
		//private function update():void 
		//{
			var dist:Number;
			p0 = new Point( _stage.mouseX, _stage.mouseY );
			var max:int = 100 * 100;
			for ( var i:int = 0; i < points.length; i++ )
			{
				
				canvas.graphics.clear();
				p0 = points[ i ];
				for ( var j:int = 0; j < points.length; j++ )
				{
					p1 = points[ j ];
					if ( p0 == p1 ) continue;
					dist = GeomUtils.squareDistance( p0.x, p0.y, p1.x, p1.y );
					
					if( dist < max )
					{
						
						canvas.graphics.lineStyle( 2, color , 1 - dist / max );
						canvas.graphics.moveTo( p0.x, p0.y );
						canvas.graphics.lineTo( p1.x, p1.y );
						
					}
					//canvas.graphics.lineStyle( 4, color , 1 );
					//canvas.graphics.moveTo( p1.x, p1.y );
					//canvas.graphics.lineTo( p1.x + .5, p1.y );
				}
				canvas.graphics.beginFill( color );
				canvas.graphics.drawCircle( p0.x, p0.y, 5 );
				canvas.graphics.endFill( );
				
				bd.draw( canvas );
			}
			
		}
		
	}

}